﻿Imports System
Imports System.IO
Imports System.Data.OleDb
Imports System.Data
Namespace Arwani
    Partial Class _Product_Signle
        Inherits System.Web.UI.Page
        Protected str_Script As String = ""
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            If IsPostBack Then Exit Sub

            Call loadData()
        End Sub
        Public Sub loadData()
            Dim arwCon As New ArwaniController
            Dim strQ As String = "select p.* from product p where  p.brandid=" & CInt(Request.QueryString("bid"))
            Dim dtTable As DataTable = arwCon.ExecuteQuery(strQ)

            Me.dgProducts.DataSource = dtTable
            Me.dgProducts.DataBind()
        End Sub
        Public Function getImage(ByVal imgSrc As String) As String
            Dim strReturn As String = "images/main_banner.png"
            If File.Exists(Server.MapPath("Products/" & imgSrc)) Then
                strReturn = "Products/" & imgSrc
            End If
            Return strReturn
        End Function

        Protected Sub dgProducts_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgProducts.ItemDataBound
            Try
                Dim hidF As HiddenField = CType(e.Item.FindControl("hidF"), HiddenField)
                Dim arwCon As New ArwaniController
                Dim strQ As String = "select pi.productimage  from product_images pi  where pi.productid=" & CInt(hidF.Value)
                Dim dtTable As DataTable = arwCon.ExecuteQuery(strQ)

                Dim iCount As Integer = 0
                Dim strArray As String = ""
                For iCount = 0 To dtTable.Rows.Count - 1
                    strArray &= "['Products/Thumb_Single_" & dtTable.Rows(iCount)("productimage") & "', '', '', ''],"
                Next
                If strArray <> "" Then
                    strArray = strArray.Substring(0, strArray.Length - 1)
                    Dim strScript As String = ""
                    strScript = "var mygallery_" & hidF.Value & " = new simpleGallery({"
                    strScript &= "wrapperid: 'simplegallery_" & hidF.Value & "', "
                    strScript &= "dimensions: [953, 225], "
                    strScript &= "imagearray: ["
                    strScript &= strArray
                    strScript &= "],"
                    strScript &= "autoplay: [true, 2500, 200], "
                    strScript &= "persist: false, "
                    strScript &= "fadeduration: 500,"
                    strScript &= "oninit: function () {},"
                    strScript &= "onslide: function (curslide, i) {}"
                    strScript &= "})"
                    str_Script &= strScript & vbCrLf
                End If

            Catch ex As Exception

            End Try
        End Sub

        Public Function getDesc(ByVal strDesc As String) As String
            Return strDesc.Replace("_x000d_", "")
        End Function

        Protected Sub dgProducts_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles dgProducts.PageIndexChanged
            Me.dgProducts.CurrentPageIndex = e.NewPageIndex
            Call loadData()
        End Sub
    End Class
End Namespace